package com.cloudsigns.factorymanager2.produce.bean.request;

import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class WorkPartScheduleItemRequest implements Serializable {
    private String orderId;
    private String productId;
    private String workPartId;
    private List<ScheduleDay> workPartScheduleItemRequestList = new ArrayList<>();

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getProductId() {
        return productId;
    }

    public void setProductId(String productId) {
        this.productId = productId;
    }

    public String getWorkPartId() {
        return workPartId;
    }

    public void setWorkPartId(String workPartId) {
        this.workPartId = workPartId;
    }

    public List<ScheduleDay> getWorkPartScheduleItemRequestList() {
        return workPartScheduleItemRequestList;
    }

    public void setWorkPartScheduleItemRequestList(List<ScheduleDay> workPartScheduleItemRequestList) {
        this.workPartScheduleItemRequestList = workPartScheduleItemRequestList;
    }

    /**
     * 获得指定日期的后n天
     *
     * @param timeStart
     * @param days      延后天数
     * @return
     */
    public String getSpecifiedDayAfter(long timeStart, int days) {
        Calendar calendar = Calendar.getInstance();
        Date date = null;
        try {
            date = new SimpleDateFormat("yy-MM-dd").parse(DateUtil.getYyyy_Mm_Dd(timeStart));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        calendar.setTime(date);

        int day = calendar.get(Calendar.DATE);
        calendar.set(Calendar.DATE, day + days);

        String dayAfter = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        workPartScheduleItemRequestList.clear();
        for (int i = 0; i < days; i++) {
            ScheduleDay sd = new ScheduleDay();
            sd.setScheduleDate(timeStart + i * 24 * 3600 * 1000);
            workPartScheduleItemRequestList.add(sd);
        }
        return dayAfter;
    }

}


